package com.leyou.item.contorller;

import com.leyou.item.service.Impl.UploadServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * Author: Saka
 * Date: 2019/1/17
 * Time: 20:59
 */
@RestController
@RequestMapping("upload")
public class UploadController {

    @Autowired
    private UploadServiceImpl uploadService;
    

    /**
     * 上传图片
     */
    @PostMapping("image")
    public ResponseEntity<String> uploadImage(@RequestParam("file") MultipartFile file) {

        String url = this.uploadService.upload(file);
        if (StringUtils.isNoneBlank(url)) {

            return ResponseEntity.ok(url);
        }
        return ResponseEntity.status(HttpStatus.BAD_REQUEST).build();
    }


}
